package xiegd.study;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2023/9/1 16:35
 */
import java.util.*;
import java.util.stream.Collectors;

class MyObject {
    private List<String> list;

    public MyObject(List<String> list) {
        this.list = list;
    }

    public List<String> getList() {
        return list;
    }

    @Override
    public String toString() {
        return "MyObject{" + "list=" + list + '}';
    }
}

public class Main4 {

    public static void main(String[] args) {

        Comparator<MyObject> compareLists = (o1, o2) -> {
            int size1 = o1.getList().size();
            int size2 = o2.getList().size();
            return Integer.compare(size1, size2);
        };


        List<MyObject> objects = new ArrayList<>();
        objects.add(new MyObject(Arrays.asList("a", "b", "c")));
        objects.add(new MyObject(Arrays.asList("d")));
        objects.add(new MyObject(Arrays.asList("e", "f", "g", "h")));

        List<MyObject> sortedObjects = objects.stream()
                .sorted(compareLists)
                .collect(Collectors.toList());

        System.out.println(sortedObjects);
    }
}
